package com.atguigu.boot.controller;


import com.atguigu.boot.bean.User;
import com.atguigu.boot.dto.Result;
import com.atguigu.boot.dto.ResultCodeEnum;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
public class HelloController {

    @RequestMapping("/bug.jpg")
    public String hello(){
        //request
        return "aaaa";
    }


//    @RequestMapping(value = "/user",method = RequestMethod.GET)
    @GetMapping("/user")
    public String getUser(){

        return "GET-张三";
    }

//    @RequestMapping(value = "/user",method = RequestMethod.POST)
    @PostMapping("/user")
    public String saveUser(){
        return "POST-张三";
    }


//    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    @PutMapping("/user")
    public String putUser(){

        return "PUT-张三";
    }

    @DeleteMapping("/user")
//    @RequestMapping(value = "/user",method = RequestMethod.DELETE)
    public String deleteUser(){
        return "DELETE-张三";
    }

    //扩展点：如何把 _method 这个名字换成我们自己喜欢的


    @GetMapping(value = "/myTest")
    public Result myTest1(){
        List<User> personList = new ArrayList<>();
        personList.add(new User("zhangSan", 14));
        personList.add(new User("liSi", 21));
        //return Result.ok().data("users", personList).message("用户列表信息");
        return Result.setResult(ResultCodeEnum.SUCCESS).data("users", personList).message("用户列表信息");
    }


}
